package com.hdaccp.shuiguoD.controller;

import com.hdaccp.shuiguoD.dao.ShangpinDao;
import com.hdaccp.shuiguoD.entity.Shangpin;
import com.hdaccp.shuiguoD.service.ShangpinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/shangpin")
@Scope("prototype")
public class ShangpinController {
    @Autowired
    private ShangpinService shangpinService;
    @Autowired
    private ShangpinDao shangpinDao;

    @RequestMapping("/getAll")
    @ResponseBody
    public List<Shangpin> getAll() {
        return shangpinService.getAll() ;
    }

    @RequestMapping("/queryAll")
    @ResponseBody
    public Map<String,Object> queryAll(int offset, int limit){
       /* Map<String,Object> map = new HashMap<>() ;
        map.put("rows",userInfoService.findAll(offset,limit)) ;
        map.put("total",userInfoService.findTotalCount()) ;
        return  map ;*/

        return  null ;
    }

    @RequestMapping("/querySearch")
    @ResponseBody
    public Map<String,Object> querySearch(String sname,int offset, int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",shangpinService.findAll(sname,offset,limit)) ;
        map.put("total",shangpinService.findTotalCount(sname)) ;
        return  map ;

    }

    @RequestMapping("/getsid")
    @ResponseBody
    public Shangpin getsid(int sid){
        return shangpinService.getsid(sid);
    }

    @RequestMapping("/add1")
    @ResponseBody
    public int add(Shangpin shangpin){
        return shangpinDao.add(shangpin);
    }

}
